package com.example.redis.myspringredis;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2017/1/11 0011.
 */

@Controller
public class DemoInfoController {

    @Resource
    DemoInfoService demoInfoService;

    @RequestMapping("/test")
    public @ResponseBody String test(){
        System.out.println("---------> ppppppp");
        DemoInfo loaded = demoInfoService.findById(1);//从数据库获取放到缓存
        System.out.println("loaded="+loaded);
        DemoInfo cached = demoInfoService.findById(1);//从缓存获取
        System.out.println("cached="+cached);
        loaded = demoInfoService.findById(2);//从db获取
        System.out.println("loaded2="+loaded);
        return"ok";
    }


    @RequestMapping("/delete")
    public@ResponseBody String delete(long id){
        demoInfoService.deleteFromCache(id);
        return"ok";
    }

    @RequestMapping("/test1")
    public@ResponseBody String test1(){
        demoInfoService.test();
        System.out.println("DemoInfoController.test1()");
        return"ok";
    }



}
